using System.Windows;

namespace CodRevit.Views
{
    public partial class InputKeyWindow : Window
    {
        public string Key { get; private set; }
        public bool IsConfirmed { get; private set; }
        public bool IsEncrypting { get; set; }

        public InputKeyWindow(bool isEncrypting = false)
        {
            InitializeComponent();
            IsEncrypting = isEncrypting;
            DataContext = this;
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(PasswordBox.Password))
            {
                MessageBox.Show("密钥不能为空。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (IsEncrypting && !ConfirmCheckBox.IsChecked == true)
            {
                MessageBox.Show("请确认已记住密钥。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Key = PasswordBox.Password;
            IsConfirmed = true;
            DialogResult = true;
            Close();
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}